package com.example.demo.service.impl;

import com.example.demo.mapper.StuComMapper;
import com.example.demo.pojo.Account;
import com.example.demo.pojo.Competition;
import com.example.demo.pojo.StuCom;
import com.example.demo.pojo.vo.Count;
import com.example.demo.service.StuComService;
import com.example.demo.utils.JwtUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StuComServiceImpl implements StuComService {
    @Autowired
    private StuComMapper stuComMapper;
    @Autowired
    private JwtUtil jwtUtil;

    @Override
    public PageInfo<StuCom> listCom(String token, Competition competition) {
        Account account = jwtUtil.parseToken(token, Account.class);
        Integer id = account.getId();
        String cname = competition.getCname();
        List<StuCom>list=stuComMapper.listCom(id,cname);
        return new PageInfo<>(list);
    }

    @Override
    public int addStuCom(StuCom stuCom) {
        return stuComMapper.addStuCom(stuCom);
    }

    @Override
    public PageInfo<StuCom> listStudent(Integer id, String username) {

        List<StuCom>list=stuComMapper.listStudent(id,username);
        return new PageInfo<>(list);
    }

    @Override
    public int upload(StuCom stuCom) {
        return stuComMapper.upload(stuCom);
    }

    @Override
    public int givePrize(Integer studentId, Integer competitionId) {
        return stuComMapper.givePrize(studentId,competitionId);
    }

}
